<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>3D Cube Rotation</title>
  <style>
    .container {
      perspective: 800px;
      margin: 100px auto;
      width: 200px;
      height: 200px;
    }

    .cube {
      width: 100%;
      height: 100%;
      position: relative;
      transform-style: preserve-3d;
      transition: transform 1s;
    }

    .face {
      position: absolute;
      width: 100%;
      height: 100%;
      opacity: 0.8;
    }

    .front {
      background-color: #4CAF50;
      transform: translateZ(100px);
    }

    .back {
      background-color: #FF9800;
      transform: rotateY(180deg) translateZ(100px);
    }

    .right {
      background-color: #2196F3;
      transform: rotateY(90deg) translateZ(100px);
    }

    .left {
      background-color: #9C27B0;
      transform: rotateY(-90deg) translateZ(100px);
    }

    .top {
      background-color: #E91E63;
      transform: rotateX(90deg) translateZ(100px);
    }

    .bottom {
      background-color: #673AB7;
      transform: rotateX(-90deg) translateZ(100px);
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="cube" id="cube">
      <div class="face front"></div>
      <div class="face back"></div>
      <div class="face right"></div>
      <div class="face left"></div>
      <div class="face top"></div>
      <div class="face bottom"></div>
    </div>
  </div>
  <button onclick="rotateCube()">加一圈</button>
  <script>
    // 初始化旋转角度为 0
    let currentRotation = 0;
    function rotateCube() {
      const cube = document.getElementById('cube');
      // 每次点击增加 360 度，绕 X 轴旋转
      currentRotation += 360;
      // 设置新的旋转角度
      cube.style.transform = `rotateX(${currentRotation}deg)`;
    }
  </script>
</body>

</html>    